#!/usr/bin/env bash

classpath="lib/dom4j-1.6.1.jar:lib/poi-2.5.1.jar:lib/poi-ooxml-3.7-20101029.jar:lib/poi-ooxml-schemas-3.7-20101029.jar:lib/mysql-connector-java-8.0.22.jar:lib/xmlbeans-2.3.0.jar"
javamain="src/org/mysql/document/tool/MysqlDGToolGUI.java"
dist="out"

if [ -d $dist ]; then
    $(rm -r $dist)
fi

$( mkdir $dist )

$(javac -classpath $classpath:src $javamain -d $dist)

case $1 in
"jar")
  echo "cd $dist"
  cd $dist
  jar -cvmf ../MANIFEST.MF mysql-gen-doc.jar .
  java -jar mysql-gen-doc.jar
  ;;
*)
  java -classpath $classpath:out org.mysql.document.tool.MysqlDGToolGUI
  ;;
esac